<?php
include '../class/class.buatpdf.php';
include '../class/class.usulan.php';
include '../class/class.detail.php';
include '../class/class.pegawai.php';
include '../class/class.refcuti.php';
include '../class/class.tujuan.php';
include '../class/class.golongan.php';
include '../class/class.jabatan.php';
include '../class/class.level.php';
include '../class/class.kanwil.php';

if(isset($_REQUEST['cetak_surat'])){
	$det=$_POST['details'];

    $details=explode(',',$det);

    $pdf=new BuatPdf();

    $data=array();
    $detailDao=array();
    $pegawaiDao =array();
    $pegawai=array();
    $cuti=array();
    $tujuan=array();
    $golDao=array();
    $jabatanDao=array();
    $gol=array();

    $detail=array();
    for($i=0;$i<count($details);$i++){
    	$detailDao[$i] = new DetailDao();
    	$detail[$i] = $detailDao[$i]->getDetailById($details[$i]);

    	$tgl_mulai = $detail[$i]['tgl_mulai'];
	    $tgl_selesai = $detail[$i]['tgl_selesai'];
	    $id_cuti = $detail[$i]['id_cuti'];
	    $id_tujuan = $detail[$i]['id_tujuan'];
	    $pegawaiDao[$i] = new PegawaiDao();
	    $nip = $detail[$i]['nip'];
	    $id_tanggapan=$detail[$i]['id_tanggapan'];
	    $keterangan=$detail[$i]['keterangan'];
	    $nama_dokumen=$detail[$i]['nama_dokumen'];
	    $pegawai[$i] = $pegawaiDao[$i]->getPegawai($nip);
	    $nama = $pegawai[$i]['nama'];
	    $kdgol = $pegawai[$i]['gol'];
	    $unit = $pegawai[$i]['unit'];
	    $eselon = $pegawai[$i]['eselon'];

	    $cuti[$i] = new RefCutiDao();
	    $tujuan[$i] = new TujuanDao();
	    $golDao[$i] = new GolonganDao();
	    $jabatanDao[$i]=new JabatanDao();
	    $gol[$i]=$golDao[$i]->getGolongan($kdgol);
	    $nama_gol=$gol[$i]['nmgol'];
	    $pangkat=$gol[$i]['pangkat'];
	    $data[$i] = array(
	        //'msg' => $msg,
	        'tgl_mulai' => $tgl_mulai,
	        'tgl_selesai' => $tgl_selesai,
	        'id_cuti' => $cuti[$i]->getCuti($id_cuti),
	        'id_tujuan' => $tujuan[$i]->getTujuan($id_tujuan),
	        'nip' => $nip,
	        'nama' => $nama,
	        'golongan' => $nama_gol,
	        'pangkat' => $pangkat,
	        'unit' => $unit,
	        'eselon' => $jabatanDao[$i]->getJabatan($nip),
	        'id_tanggapan' => $id_tanggapan,
	        'keterangan' => $keterangan,
	        'nama_dokumen' => $nama_dokumen,
	    );
    }

    $pdf->createSurat($data);
}

if(isset($_REQUEST['cetak_surat_doc'])){

	include_once('../class/tbs_class.php');
	include_once('../class/plugins/tbs_plugin_opentbs.php');
	
	$det=$_POST['details'];

    $details=explode(',',$det);

    $pdf=new BuatPdf();

    $data=array();
    $detailDao=array();
    $pegawaiDao =array();
    $pegawai=array();
    $cuti=array();
    $tujuan=array();
    $golDao=array();
    $jabatanDao=array();
    $gol=array();

    $detail=array();
    for($i=0;$i<count($details);$i++){
    	$detailDao[$i] = new DetailDao();
    	$detail[$i] = $detailDao[$i]->getDetailById($details[$i]);

    	$tgl_mulai = $detail[$i]['tgl_mulai'];
	    $tgl_selesai = $detail[$i]['tgl_selesai'];
	    $id_cuti = $detail[$i]['id_cuti'];
	    $id_tujuan = $detail[$i]['id_tujuan'];
	    $pegawaiDao[$i] = new PegawaiDao();
	    $nip = $detail[$i]['nip'];
	    $id_tanggapan=$detail[$i]['id_tanggapan'];
	    $keterangan=$detail[$i]['keterangan'];
	    $nama_dokumen=$detail[$i]['nama_dokumen'];
	    $pegawai[$i] = $pegawaiDao[$i]->getPegawai($nip);
	    $nama = $pegawai[$i]['nama'];
	    $kdgol = $pegawai[$i]['gol'];
	    $unit = $pegawai[$i]['unit'];
	    $eselon = $pegawai[$i]['eselon'];

	    $cuti[$i] = new RefCutiDao();
	    $tujuan[$i] = new TujuanDao();
	    $golDao[$i] = new GolonganDao();
	    $jabatanDao[$i]=new JabatanDao();
	    $gol[$i]=$golDao[$i]->getGolongan($kdgol);
	    $nama_gol=$gol[$i]['nmgol'];
	    $pangkat=$gol[$i]['pangkat'];
	    $data[$i] = array(
	        //'msg' => $msg,
	        'tgl_mulai' => $tgl_mulai,
	        'tgl_selesai' => $tgl_selesai,
	        'id_cuti' => $cuti[$i]->getCuti($id_cuti),
	        'id_tujuan' => $tujuan[$i]->getTujuan($id_tujuan),
	        'nip' => $nip,
	        'nama' => $nama,
	        'golongan' => $nama_gol,
	        'pangkat' => $pangkat,
	        'unit' => $unit,
	        'eselon' => $jabatanDao[$i]->getJabatan($nip),
	        'id_tanggapan' => $id_tanggapan,
	        'keterangan' => $keterangan,
	        'nama_dokumen' => $nama_dokumen,
	    );
    }

    //$pdf->createSuratDoc($data);
}

if(isset($_REQUEST['cetak_surat_doc2'])){

	include_once('../class/tbs_class.php');
	include_once('../class/plugins/tbs_plugin_opentbs.php');
	include_once('../class/lib.tanggal.php');
	include_once('../class/class.jabatan.php');
	
	
	$TBS = new clsTinyButStrong;
	$TBS->Plugin(TBS_INSTALL, OPENTBS_PLUGIN);
	$det=$_POST['cetak_surat_doc2'];

    	$detailDao = new DetailDao();
    	$detail = $detailDao->getDetailById($det);

    	$tanggal= new Tanggal();

    	$tglAwal = $tanggal->formatTanggalTanpaHari($detail['tgl_mulai']);
	    $tglAkhir = $tanggal->formatTanggalTanpaHari($detail['tgl_selesai']);
		$tglSkrg=$tanggal->formatTanggalTanpaHari(date('Y-m-d'));

		$tahun=date('Y');

		$jabatanDao=new JabatanDao();
		$cuti = new RefCutiDao();
	    $tujuan = new TujuanDao();
	    $golDao = new GolonganDao();

	    $id_cuti = $detail['id_cuti'];
	    $id_tujuan = $detail['id_tujuan'];
	    $pegawaiDao = new PegawaiDao();
	    $nip = $detail['nip'];
	    
		$str=$jabatanDao->getJabatan($nip);

		$strJabatan=explode("\n", $str);

		$jabatan=$strJabatan[0];

	    $id_tanggapan=$detail['id_tanggapan'];
	    $keterangan=$detail['keterangan'];

	    $pegawai = $pegawaiDao->getPegawai($nip);

	    $nama = $pegawai['nama'];
	    $kdgol = $pegawai['gol'];
	    $unit = $pegawai['unit'];
	    $eselon = $pegawai['eselon'];

	    
	    $gol=$golDao->getGolongan($kdgol);
	    $golongan=$gol['nmgol'];
	    $pangkat=$gol['pangkat'];

	    $TBS->LoadTemplate('../assets/surat.docx');

		$file_name = 'surat'.'_'.$nip.'_'.date('Y-m-d');

		$TBS->Show(OPENTBS_DOWNLOAD, $file_name . '.docx');

}

if(isset($_REQUEST['cetak_xlx'])){
	$det=$_POST['details'];

    $details=explode(',',$det);

    $pdf=new BuatPdf();

    $data=array();
    $detailDao=array();
    $pegawaiDao =array();
    $pegawai=array();
    $cuti=array();
    $tujuan=array();
    $golDao=array();
    $jabatanDao=array();
    $gol=array();

    $detail=array();
    for($i=0;$i<count($details);$i++){
    	$detailDao[$i] = new DetailDao();
    	$detail[$i] = $detailDao[$i]->getDetailById($details[$i]);

    	$tgl_mulai = $detail[$i]['tgl_mulai'];
	    $tgl_selesai = $detail[$i]['tgl_selesai'];
	    $id_cuti = $detail[$i]['id_cuti'];
	    $id_tujuan = $detail[$i]['id_tujuan'];
	    $pegawaiDao[$i] = new PegawaiDao();
	    $nip = $detail[$i]['nip'];
	    $id_tanggapan=$detail[$i]['id_tanggapan'];
	    $keterangan=$detail[$i]['keterangan'];
	    $nama_dokumen=$detail[$i]['nama_dokumen'];
	    $pegawai[$i] = $pegawaiDao[$i]->getPegawai($nip);
	    $nama = $pegawai[$i]['nama'];
	    $kdgol = $pegawai[$i]['gol'];
	    $unit = $pegawai[$i]['unit'];
	    $eselon = $pegawai[$i]['eselon'];

	    $cuti[$i] = new RefCutiDao();
	    $tujuan[$i] = new TujuanDao();
	    $golDao[$i] = new GolonganDao();
	    $jabatanDao[$i]=new JabatanDao();
	    $gol[$i]=$golDao[$i]->getGolongan($kdgol);
	    $nama_gol=$gol[$i]['nmgol'];
	    $pangkat=$gol[$i]['pangkat'];
	    $data[$i] = array(
	        //'msg' => $msg,
	        'tgl_mulai' => $tgl_mulai,
	        'tgl_selesai' => $tgl_selesai,
	        'id_cuti' => $cuti[$i]->getCuti($id_cuti),
	        'id_tujuan' => $tujuan[$i]->getTujuan($id_tujuan),
	        'nip' => $nip,
	        'nama' => $nama,
	        'golongan' => $nama_gol,
	        'pangkat' => $pangkat,
	        'unit' => $unit,
	        'eselon' => $jabatanDao[$i]->getJabatan($nip),
	        'id_tanggapan' => $id_tanggapan,
	        'keterangan' => $keterangan,
	        'nama_dokumen' => $nama_dokumen,
	    );
    }

    $pdf->cetakXls($data);
}

?>